import * as echarts from 'echarts'

function create(name, data){
    const chart = echarts.init(document.querySelector(name));
    let numData = []
    for(let i in data.label_num){
        let da = {}
        da.name = i
        da.value = data.label_num[i]
        numData.push(da)
    }

    let option = {
        title: {
            text: '各类别的连通域数量',
            subtext: '',
            left: 'center',
            textStyle: {
                color: 'white' // 设置标题文字颜色为红色
            },
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            left: 'center',
            top: 'bottom',
            data: []
        },
        toolbox: {
            show: true,
            feature: {
                mark: { show: true },
                dataView: { show: true, readOnly: false },
                restore: { show: true },
                saveAsImage: { show: true }
            }
        },
        series: [
            {
                name: '连通域数量',
                type: 'pie',
                radius: [20, 140],
                roseType: 'area',
                itemStyle: {
                    borderRadius: 5
                },
                data: numData
            }
        ]
    };
    chart.setOption(option)
}

export default {
    create
}